package lt.liepasoft.sudoku.component;

import java.util.Map;

import lt.liepasoft.sudoku.SudokuTable;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;

public class PaintNumbers extends PaintComponent {

	private SudokuTable table;
	private int textOffX,textOffY; 
	public PaintNumbers(Map<Data, Integer> options, SudokuTable table) {
		super(options);
		paint = new Paint();
		paint.setTextSize(options.get(Data.TEXT_SIZE));
		paint.setTextAlign(Align.CENTER);
		paint.setStyle(Style.FILL_AND_STROKE);
		textOffX = options.get(Data.CELL_WIDTH)/2;
		textOffY = options.get(Data.CELL_HEIGHT)/2;
		this.table = table;		
	}

	public void setTable(SudokuTable table) {
		this.table = table;
	}
	
	public SudokuTable getTable() {
		return table;
	}
	
	@Override
	public void paint(Canvas canvas) {
		for (int y=0; y<9; y++){
			for (int x=0; x<9; x++){
				if (table.getCell(x, y) != 0)
				canvas.drawText(
						table.getCell(x, y)+"", 
						options.get(Data.GRID_OFFSET_X)+options.get(Data.CELL_WIDTH)*x+textOffX, 
						options.get(Data.GRID_OFFSET_Y)+options.get(Data.CELL_HEIGHT)*(y+1)-3, 
						paint);
			}
		}
	}

}
